package com.cate.controller.user;

import com.cate.base.BasePageVO;
import com.cate.mapper.OrderDetailMapper;
import com.cate.pojo.dto.*;
import com.cate.pojo.entity.OrderDetail;
import com.cate.pojo.entity.Orders;
import com.cate.pojo.vo.OrderPaymentVO;
import com.cate.pojo.vo.OrderSubmitVO;
import com.cate.pojo.vo.OrderVO;
import com.cate.result.RestResponse;
import com.cate.service.OrdersService;
import com.cate.utils.ResultUtil;
import com.github.pagehelper.PageHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @CreateTime: 2023/8/1
 * @Author: <==lhd==>
 * @Description:
 */

@RestController("UserOrderController")
@Slf4j
@RequestMapping("/user/order")
@Api(tags = "用户端订单接口")
public class OrderController {
    @Autowired
    private OrdersService ordersService;

    @PutMapping("/cancel/{id}")
    @ApiOperation("取消订单")
    public RestResponse cancelOrder(@PathVariable("id") Long id) {
        OrdersCancelDTO ordersCancelDTO = new OrdersCancelDTO();
        ordersCancelDTO.setId(id);
        ordersCancelDTO.setCancelReason("");
        ordersService.cancelOrder(ordersCancelDTO);
        return ResultUtil.success("");
    }

    @PostMapping("/repetition/{id}")
    @ApiOperation("再来一单")
    public RestResponse repetitionOrder(@PathVariable("id") Long id) {
        ordersService.repetitionOrder(id);
        return ResultUtil.success("");
    }

    @GetMapping("/historyOrders")
    @ApiOperation("历史订单查询")
    public RestResponse<BasePageVO<OrderVO>> getHistoryOrders(int page, int pageSize, Integer status) {
        final BasePageVO<OrderVO> voBasePageVO = ordersService.pageQueryForUser(page, pageSize, status);
        log.info("voBasePageVO={}",voBasePageVO);
        return ResultUtil.success(voBasePageVO);
    }

    @PostMapping("/submit")
    @ApiOperation("用户下单")
    public RestResponse<OrderSubmitVO> submitOrder(@RequestBody OrdersSubmitDTO ordersSubmitDTO) {
        final OrderSubmitVO orderSubmitVO = ordersService.submitOrder(ordersSubmitDTO);
        return ResultUtil.success(orderSubmitVO);
    }

    @GetMapping("/orderDetail/{id}")
    @ApiOperation("查询订单详情")
    public RestResponse<OrderVO> getOrderDetail(@PathVariable("id") Long id) {
        final OrderVO orderVO = ordersService.getOrdersById(id);
        return ResultUtil.success(orderVO);
    }

    @GetMapping("/reminder/{id}")
    @ApiOperation("催单")
    public RestResponse<Object> reminderOrder(@PathVariable("id") Long id){
        ordersService.reminderOrder(id);
        return ResultUtil.success("");
    }

    @PutMapping("/payment")
    @ApiOperation("订单支付")
    public RestResponse<Object> paymentOrder(@RequestBody OrdersPaymentDTO ordersPaymentDTO){
        ordersService.paymentOrder(ordersPaymentDTO);
        log.info("{}",ordersPaymentDTO);
        return ResultUtil.success("");
    }
}
